package com.va1m.demo.common;

import lombok.Data;

/**
 * 统一返回结果类
 * @author Admin
 */
@Data
public class Result<T> {
    private T data;
    private Boolean success;
    public Result(){}

    /**
     * 返回数据正常数据
     * @param data
     * @param <T>
     * @return
     */
    public static <T> Result<T> ok(T data) {
        Result<T> result = new Result<T>();
        if (data != null){
            result.setData(data);
            result.setSuccess(true);
        }
        return result;
    }

    /**
     * 返回异常信息
     * @param data
     * @param <T>
     * @return
     */
    public static<T> Result<T> fail(T data){
        Result<T> result = new Result<T>();
        result.setData(data);
        result.setSuccess(false);
        return result;
    }
}
